package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Skill;
import com.ruoyi.system.service.ISkillService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 技能档案Controller
 * 
 * @author 503
 * @date 2021-05-04
 */
@Controller
@RequestMapping("/system/skill")
public class SkillController extends BaseController
{
    private String prefix = "system/skill";

    @Autowired
    private ISkillService skillService;

    @RequiresPermissions("system:skill:view")
    @GetMapping()
    public String skill()
    {
        return prefix + "/skill";
    }

    /**
     * 查询技能档案列表
     */
    @RequiresPermissions("system:skill:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Skill skill)
    {
        startPage();
        List<Skill> list = skillService.selectSkillList(skill);
        return getDataTable(list);
    }

    /**
     * 导出技能档案列表
     */
    @RequiresPermissions("system:skill:export")
    @Log(title = "技能档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Skill skill)
    {
        List<Skill> list = skillService.selectSkillList(skill);
        ExcelUtil<Skill> util = new ExcelUtil<Skill>(Skill.class);
        return util.exportExcel(list, "技能档案数据");
    }

    /**
     * 新增技能档案
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存技能档案
     */
    @RequiresPermissions("system:skill:add")
    @Log(title = "技能档案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Skill skill)
    {
        return toAjax(skillService.insertSkill(skill));
    }

    /**
     * 修改技能档案
     */
    @GetMapping("/edit/{skillId}")
    public String edit(@PathVariable("skillId") Long skillId, ModelMap mmap)
    {
        Skill skill = skillService.selectSkillById(skillId);
        mmap.put("skill", skill);
        return prefix + "/edit";
    }

    /**
     * 修改保存技能档案
     */
    @RequiresPermissions("system:skill:edit")
    @Log(title = "技能档案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Skill skill)
    {
        return toAjax(skillService.updateSkill(skill));
    }

    /**
     * 删除技能档案
     */
    @RequiresPermissions("system:skill:remove")
    @Log(title = "技能档案", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(skillService.deleteSkillByIds(ids));
    }
}
